<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>Mua~亲亲宠————发货</title>
<link rel="stylesheet" href="css/style.css" />

<link rel="stylesheet" href="css/bootstrap.css" />

<link rel="stylesheet" href="css/bootstrapValidator.css" />

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>
</head>

<body>
	<%@ include file="/WEB-INF/jsp/top.jspf"%>
	<div class="title"></div>
	<div class="container  col-sm-offset-2  col-sm-8">
		<div class="page-header" style="color:#000099">
			<h3>发货信息</h3>
		</div>
		<form id="sendForm" class="form-horizontal">
			<div class="form-group">
				<label class="control-label">订单号：${order.orderNo}</label>
			</div>
			<div class="form-group">
				<label class="control-label">出售宠物：${order.petTitle}</label>
			</div>
			<input type="hidden" name="orderId" value="${order.id}">
			<div class="form-group">
				<label class="col-sm-4 control-label">输入快递号（无快递号可填写"0000000000"）：</label>
				<div class="col-sm-7">
					<input type="text" name="experssNo" class="form-control" />
				</div>
			</div>
			<div class="col-sm-offset-2 col-sm-3">
				<button type="button" class="btn btn-info"
					onclick="checkAndSubmit()">确认发货信息</button>
			</div>
		</form>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {
			$('#sendForm').bootstrapValidator({
				message : 'This value is not valid',
				feedbackIcons : {
					valid : 'glyphicon glyphicon-ok',
					invalid : 'glyphicon glyphicon-remove',
					validating : 'glyphicon glyphicon-refresh'
				},
				fields : {
					experssNo : {
						message : '',
						validators : {
							notEmpty : {
								message : '快递信息不能为空'
							},
							stringLength : {
								min : 10,
								max : 30,
								message : '快递号最少10位，最多30位'
							},
						}
					}
				}
			});

		});
		function checkAndSubmit() {
			$("#sendForm").bootstrapValidator('validate');//提交验证  
			if ($("#sendForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码  
				$.ajax({
					url : "order/send.do",
					data : $("#sendForm").serialize(),
					type : "POST",
					success : function(result) {
						//请求成功时
						if (result.msg == 'success') {
							$(".modal-body").html("发货成功！点击确定前往我的订单");
							$("#topModal").modal("show");
							$("#topModal").on('hidden.bs.modal', function() {
								var gotoURL = "order/myOrders.do";
								window.location.href = gotoURL;
							});
						} else if (result.msg == 'error') {
							$(".modal-body").html(result.errorMsg);
							$("#topModal").modal("show");
						}
					},
					error : function() {
						//请求失败时
						$(".modal-body").html("提交发货信息失败");
						$("#topModal").modal("show");
					}
				});
			}
		}
	</script>
</body>
</html>
